#ifndef LOG_H
#define LOG_H
#include <syncstream>
#include <unordered_map>
#include <map>
#include <vector>
#include <memory>
#include <fstream>
#include <string>
#include <functional>
const int MAX_LOG_PRINTF_SIZE = 1024;
class Log
{
public:
    static Log& instance();
    void error(const char* data);
    void output(const char* data);
    bool setOutputFile(const std::string& logFile, std::ios::openmode mode = std::ios::trunc | std::ios::out);
    bool setErrorFile(const std::string& errorFile, std::ios::openmode mode = std::ios::trunc | std::ios::out);
    template <class T>
    void print_range(const T& r) {
        for (auto&& i : r) {
            out << i << " ";
        }
        out << std::endl;
    }
    template <class T>
    void print_kv_range(const T& r) {
        for (auto&& [k, v] : r) {
            out << k << " :" << v << std::endl;
        }
        out << std::endl;
    }
    template<class... T>
    void printf(const char* s,T... t)
    {
        char data[MAX_LOG_PRINTF_SIZE] = {0};
        snprintf(data, MAX_LOG_PRINTF_SIZE, s, t...);
        out << data;
    }
    std::osyncstream getOutput();
    std::osyncstream getError();    
    ~Log(); 

private:
    std::ofstream out,err;
    explicit Log() {};
};
#endif